package cn.hchaojie.javase.day09;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.junit.Test;

public class TestSetAndMap {
	@Test
	public void test1() {
		Set<Student> set = new HashSet<>();
		set.add(new Student("张三", 88));
		set.add(new Student("张三", 88));
		
		System.out.println(set.size());
	}
	
	// set集合遍历，两种方式
	@Test
	public void test2() {
		Set<Student> set = new HashSet<>();
		set.add(new Student("张三", 88));
		set.add(new Student("李四", 88));
		
		// set集合里面的元素，不能按下标取
		// set集合元素是无序的

//		for (int i = 0; i < set.size(); i++) {
//		}
		
		for (Student s : set) {
			System.out.println(s);
		}
		
		Iterator<Student> iterator = set.iterator();
		while (iterator.hasNext()) {
			Student next = iterator.next();
			System.out.println(next);
		}
	}
	
	@Test
	public void test3() {
		int[] array = {10, 5, 39, 15, 8, 5, 8};
		
		Set<Integer> set = new HashSet<>();
		for (int i = 0; i < array.length; i++) {
			set.add(array[i]);
		}
		
		System.out.println(set.size());
	}
}
